<?php
/*
 * 评论页
 * @package    auto
 * @author     Sameal
 * @copyright  Copyright (c) 2013 ixdcw team
 * @version
 */
defined('IN_IXDCW') or exit('Access Denied');
require_once DT_CORE."/{$module}/common.inc.php";

// header
$headerPart = 'comment';
require_once MD_ROOT . '/header.inc.php';

//读取中文返回信息
include load('autoComment.lang');
//检查是否提交评论表单
$sbt        = isset($_POST['auto-score-sbt']) ? $_POST['auto-score-sbt'] : 0;
if($sbt){
	//用户是否登录
	if(!$_userid){
		include template('nologin', 'message');
		exit;
	}
	//初始化评论数据
	$post['userid']          = $_userid;
	$post['app']             = isset($_POST['app-score'])       &&$_POST['app-score']!=0        ? $_POST['app-score'] : 5;
	$post['arbid']           = isset($brandId)      ?$brandId:      0;
	$post['armid']           = isset($manufactorId) ?$manufactorId: 0;
	$post['arcid']           = isset($carId)        ?$carId:        0;
	$post['amid']            = isset($modelId)      ? $modelId :    0;
	$post['inners']          = isset($_POST['inner-score'])     &&$_POST['inner-score']!=0      ? $_POST['inner-score'] : 5;
	$post['oil']             = isset($_POST['oil-score'])       &&$_POST['oil-score']!=0        ? $_POST['oil-score'] : 5;
	$post['quality']         = isset($_POST['quality-score'])   &&$_POST['quality-score']!=0    ? $_POST['quality-score'] : 5;
	$post['config']          = isset($_POST['config-score'])    &&$_POST['config-score']!=0     ? $_POST['config-score'] : 5;
	$post['space']           = isset($_POST['space-score'])     &&$_POST['space-score']!=0      ? $_POST['space-score'] : 5;
	$post['comfort']         = isset($_POST['comfort-score'])   &&$_POST['comfort-score']!=0    ? $_POST['comfort-score'] : 5;
	$post['detail']          = isset($_POST['detail-score'])    &&$_POST['detail-score']!=0     ? $_POST['detail-score'] : 5;
	$post['speed']           = isset($_POST['speed-score'])     &&$_POST['speed-score']!=0      ? $_POST['speed-score'] : 5;
	$post['oper']            = isset($_POST['oper-score'])      &&$_POST['oper-score']!=0       ? $_POST['oper-score'] : 5;
	$post['noise']           = isset($_POST['noise-score'])     &&$_POST['noise-score']!=0      ? $_POST['noise-score'] : 5;
	$post['userfeeling']     = str_replace("\n","<br />",$_POST['use-feeling']);
	// 插入
	$do = new AutoCarComment();
	$Info_back=$do->add($post);
	//提交按钮卸载
	unset($_POST['auto-score-sbt']);
	//判段数据是否提交成功 跳转到不同返回页
	if($Info_back==1){
		if($modelId){
			$dforward=url('auto/carCommentShow', 'modelid='.$modelId);
		}else{
			$dforward=url('auto/carCommentShow', 'carid='.$carId);
		}
		$dmessage=$OK;
		include template('submitOK', 'message');
	}else{
		switch ($Info_back)
		{
			case 'ALL':
				$dmessage=$ERROR_REPEAT_ALL;
            break;
			case 'USERID':
				$dmessage=$ERROR_REPEAT_USERID;
            break;
			case 'IP':
				$dmessage=$ERROR_REPEAT_IP;
			break;
		}
		$dforward='goback';
		include template('submitERROR', 'message');
	}
}else{

		include template('comment', $module);
}
